package com.company.controller.interceptor;

import com.company.controller.result.Results;
import com.company.system.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author
 * @date 2021-07-26 11:55
 * 拦截器
 */

//  @ControllerAdvice  实现全局异常处理，只需要定义类，添加该注解即可定义方式如下：
@Component
@ControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    // 对出现异常的情况进行拦截，并将其处理成统一的页面数据结果格式
    public Results doBusinessException(BusinessException e){
        return new Results(e.getCode(),e.getMessage());
    }


}
